********************************************************************************
* ELECTORAL REPERCUSSIONS OF A PANDEMIC:  EVIDENCE FROM THE 2009 H1N1 OUTBREAK *
********************************************************************************

// NOVEMBER 2, 2021

// THIS FILE REPLICATES TABLES A1 AND A2 IN APPENDIX A OF "ELECTORAL 
// REPERCUSSIONS OF A PANDEMIC: EVIDENCE FROM THE 2009 H1N1 OUTBREAK" BY
// EMILIO GUTIÉRREZ, JAAKKO MERILÄINEN, AND ADRIÁN RUBLI

global data "XXX" // Insert data directory here
global output "XXX" // Insert output directory here

* Open data

use "$data/GMR_data_main.dta", clear

********************************************************************************

* Table A1

est clear

preserve

gen a=1 if change_ari!=. & PAN_voteshare!=.
bysort id: egen sum_a=sum(a) 
drop if sum_a<6

la var PAN_voteshare "\quad PAN vote share"
la var PRI_voteshare "\quad PRI vote share"
la var others "\quad Other parties' vote share"
la var turnout "\quad Voter turnout"
la var change_ari "\quad Excess cases (1000s)"
la var change_ari_z "\quad Excess cases (z-score)"

estpost summarize PAN_voteshare PRI_voteshare others turnout change_ari change_ari_z
esttab using "$output/tableA1.tex", replace booktabs cells("count mean(fmt(%9.2f)) sd(fmt(%9.2f))") noobs nomtitle nonumber label ///
	collabels("\textit{N}" "Mean" "Std. dev.") refcat(PAN_voteshare "\emph{Electoral outcomes}" change_ari "\emph{H1N1 exposure}", nolabel)
	
restore

* Table A2

est clear

preserve

la var PAN_voteshare "\quad PAN vote share"
la var PRI_voteshare "\quad PRI vote share"
la var others "\quad Other parties' vote share"
la var turnout "\quad Voter turnout"
la var change_ari "\quad Excess cases (1000s)"
la var change_ari_z "\quad Excess cases (z-score)"

estpost summarize PAN_voteshare PRI_voteshare others turnout change_ari change_ari_z
esttab using "$output/tableA2.tex", replace booktabs cells("count mean(fmt(%9.2f)) sd(fmt(%9.2f))") noobs nomtitle nonumber label ///
	collabels("\textit{N}" "Mean" "Std. dev.") refcat(PAN_voteshare "\emph{Electoral outcomes}" change_ari "\emph{H1N1 exposure}", nolabel)
	
restore
